<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class BlogApi extends CI_Controller{

    public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $this->load->model('blog_model');
    }

    public function blogs()
    {
        $perPage = 2;
        $pageNow = $this->uri->segment(3) ? $this->uri->segment(3) : 1;
        $firstRow = ($pageNow - 1) * $perPage;
        $data['blogs'] = $this->blog_model->getBlogNowPage($perPage, $firstRow);
        echo json_encode($data['blogs']);
    }

    public function one($id)
    {
        $query = $this->db->get_where('blog', array('id' => $id));
        $data['show'] = $query->row_array();
        echo json_encode($data['show']);
    }
}